package com.jin.lazytool.handler;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.util.Arrays;

public enum LoopType {
    // 按照次数
    COUNT("计数",new CountLoopHandler()),
    // 按照计时
    TIMER("计时",new TimerLoopHandler()),
    // js脚本
    LUA("while脚本",new LuaLoopHandler()),
    //截止系统时间
    TIME("截止时间",new TimeLoopHandler());

    private final String desc;
    private final ILoopHandler handler;

    LoopType(String name,ILoopHandler handler){
        this.desc = name;
        this.handler = handler;
    }

    public ILoopHandler getHandler() {
        return handler;
    }

    public String getDesc() {
        return desc;
    }


    public static LoopType convert(String name){
        LoopType[] values = LoopType.values();
        for (LoopType item : values) {
            if(item.getDesc().equals(name)){
                return item;
            }
        }
        return null;
    }

    public static ObservableList<LoopType> loopTypes = null;
    static{
        loopTypes = FXCollections.observableArrayList(Arrays.asList(LoopType.values()));
    }
}
